package coder.nav.model.vo;

import coder.nav.enums.NavCashFlagEnums;
import lombok.Data;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 雷达图
 * @author Bosen 2024/10/31 17:25
 */
@Data
public class NavChartRadarVO {

    private List<String> legend;

    private List<Map<String, String>> indicator;

    private List<Map<String, Object>> data;

    public NavChartRadarVO(Set<String> legend, Map<String, Map<String, BigDecimal>> data) {
        this.legend = new ArrayList<>(legend);
        this.data = new ArrayList<>();
        this.indicator = data.keySet().stream().map(item -> {
            Map<String, String> map = new HashMap<>();
            map.put("name", item);
            return map;
        }).collect(Collectors.toList());

        List<String> addList = new ArrayList<>();
        List<String> subList = new ArrayList<>();
        data.forEach((key, value) -> {
            addList.add(value.getOrDefault(NavCashFlagEnums.ADD.getValue(), BigDecimal.ZERO).toString());
            subList.add(value.getOrDefault(NavCashFlagEnums.SUB.getValue(), BigDecimal.ZERO).toString());
        });

        Map<String, Object> addMap = new TreeMap<>();
        addMap.put("name", NavCashFlagEnums.ADD.getValue());
        addMap.put("value", addList);
        this.data.add(addMap);

        Map<String, Object> subMap = new TreeMap<>();
        subMap.put("name", NavCashFlagEnums.SUB.getValue());
        subMap.put("value", subList);
        this.data.add(subMap);

    }

}
